LED1=9;LED2=9;LED3=9;LED4=9;OPEN=9;
gpio.trig(PIN_LED1_TONER,"both",function(level,pulse)
    OPEN = level
    udp_send("L1"..level)
end)
gpio.trig(PIN_LED2_DRUM,"both",function(level,pulse)
    OPEN = level
    udp_send("L2"..level)
end)
gpio.trig(PIN_LED3_PAPER,"both",function(level,pulse)
    OPEN = level
    udp_send("L3"..level)
end)
setInterval(function()
    local TADC = adc.read(0);
    local TLED4 = 3;
    if TADC < 30 then
        TLED4 = 0;
    elseif TADC > 600 then
        TLED4 = 1;
    else
        TLED4 = 2;
    end
    if TLED4 ~= LED4 then
        udp_send("L4"..TLED4);
        LED4 = TLED4;
    end
end,10)
-- GPIO1
function open()
    gpio.write(PIN_OPEN,gpio.LOW);
    setTimeout(function()
        gpio.write(PIN_OPEN,gpio.HIGH);
    end,500)
end
function close()
    gpio.write(PIN_OPEN,gpio.LOW);
    setTimeout(function()
        gpio.write(PIN_OPEN,gpio.HIGH);
    end,4000)
end
function clean()
    if Open == 1 then
        close()
        setTimeout(function()clean();end,5000)
    else
       gpio.write(2,gpio.LOW);
       gpio.write(1,gpio.LOW);
       setTimeout(function()
            if LED1 == 1 and LED2 == 1 and LED3 == 1 and LED4 ==0 then
                gpio.write(2,gpio.HIGH);            
            end 
       end,12000) 
    end    
end
function press_open_time(T)
    gpio.write(PIN_OPEN,gpio.LOW);
    setTimeout(function()
        gpio.write(PIN_OPEN,gpio.HIGH);
    end,T)
end
function press_open()
    gpio.write(PIN_OPEN,gpio.LOW);
end
function unpress_open()
    gpio.write(PIN_OPEN,gpio.HIGH);
end
function press_go_time(T)
    gpio.write(PIN_GO,gpio.LOW);
    setTimeout(function()
        gpio.write(PIN_GO,gpio.HIGH);
    end,T)
end
function press_go()
    gpio.write(PIN_GO,gpio.LOW);
end
function unpress_go()
    gpio.write(PIN_GO,gpio.HIGH);
end
